// 生成一个公共 防抖函数
export function debounce<T extends (...args: any[]) => any>(
     fn: T,
     delay: number,
) {
     let timer: NodeJS.Timeout | null = null
     return function (this: any, ...args: Parameters<T>) {
          if (timer) {
               clearTimeout(timer)
          }
          timer = setTimeout(() => {
               fn.apply(this, args)
          }, delay)
     }
}
// 生成一个公共 节流函数
export function throttle<T extends (...args: any[]) => any>(
     fn: T,
     delay: number,
) {
     let timer: NodeJS.Timeout | null = null
     return function (this: any, ...args: Parameters<T>) {
          if (timer) {
               return
          }
          fn.apply(this, args)
          timer = setTimeout(() => {
               timer = null
          }, delay)
     }
}
